package us.mooresr.aircraftscheduling.client.events;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
import us.mooresr.aircraftscheduling.shared.model.User;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.event.shared.HandlerRegistration;

public class UserCreatedEvent extends
		GwtEvent<UserCreatedEvent.UserCreatedHandler> {

	public static Type<UserCreatedHandler> TYPE = new Type<UserCreatedHandler>();
	private User user;

	public interface UserCreatedHandler extends EventHandler {
		public void onUserCreated(UserCreatedEvent event);
	}

	public interface UserCreatedHasHandlers extends HasHandlers {
		public HandlerRegistration addUserCreatedHandler(UserCreatedHandler handler);
	}

	public UserCreatedEvent(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	@Override
	protected void dispatch(UserCreatedHandler handler) {
		handler.onUserCreated(this);
	}

	@Override
	public Type<UserCreatedHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<UserCreatedHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source, User user) {
		source.fireEvent(new UserCreatedEvent(user));
	}
}
